package com.ellecity06.cwhiskymall.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.GoodImageBean
import com.ellecity06.cwhiskymall.databinding.ItemShareImageBinding

/**
 * @author ellecity06
 * @time 2024/11/4 14:50
 * @des
 */
class ShareGoodImageAdapter : BaseAdapter<GoodImageBean, ItemShareImageBinding>() {
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemShareImageBinding {
        return ItemShareImageBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(binding: ItemShareImageBinding, position: Int, item: GoodImageBean) {
        binding.tvCode.visibility = if (position==0) View.VISIBLE else View.GONE
        binding.ivGood.load(context, item.image,5F)
        binding.ivCheck.setImageResource(if (item.checked) R.mipmap.icon_check_image else  R.mipmap.icon_check_image_unselect)
    }

    fun getSelectList(): List<GoodImageBean> {
        return items.filter { it.checked }
    }

    fun check(position: Int) {
        val item = items[position]
        item.checked = !item.checked
        notifyItemChanged(position)
    }

    fun selectAll() {
        items.forEachIndexed { index, goodImageBean ->
            if (!goodImageBean.checked) {
                goodImageBean.checked = true
                notifyItemChanged(index)
            }
        }

    }


}